<?php

namespace api\libs\event\components;

use api\modules\app\models\TaskRecord;
use Yii;
use api\components\state\StateModelContext;
use yii\base\Component;
use api\libs\event\models\Event;
use api\components\Notification;
use api\modules\app\resource\EventResource;
use api\modules\app\resource\OrderResource;
use yii\db\Exception;

/**
 * 事件监听类用于状态改变
 *
 * @author johnson
 * @date 2019-10-14
 * @access public
 */
class StateListener extends Component {

     public static function onSaveStatus($event) {
        $object = $event->sender;
        $data = $event->data;
        if (isset($data['state']) && !empty($data['state'])) {
            $stateModelContext = new StateModelContext();
            $stateModelContext->createModel($object->getStateType(), $data['state']);
            $stateModel = $stateModelContext->getModel();
            if ($stateModel) {
                 return $stateModel->update($object);
            }
        }
        return false;
    }

}
